package com.chuhe.starry;

import com.chuhe.common.constans.MyConstants;
import com.chuhe.common.utils.AppConfig;
import com.chuhe.starry.spring.ApplicationContextProvider;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.DependsOn;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.servlet.MultipartConfigElement;

/**
 * @Author: 楚河
 * @Date: 2025年05月08日9:21
 */
@EnableAsync
@SpringBootApplication(scanBasePackages = {"com.chuhe"})
@MapperScan({"com.chuhe.starry.mapper"})
@EnableTransactionManagement
@EnableScheduling
public class StarryChatApplication {
    public static void main(String[] args) {
        SpringApplication.run(StarryChatApplication.class,args);
    }
    @Bean
    @DependsOn({"applicationContextProvider"})
    MultipartConfigElement multipartConfigElement() {
        AppConfig appConfig = (AppConfig) ApplicationContextProvider.getBean("appConfig");
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setLocation(appConfig.getProjectFolder() + MyConstants.FILE_FOLDER_TEMP);
        return factory.createMultipartConfig();
    }
}
